//
//  ResourceViewController.m
//  DevIPad
//
//  Created by HuCongshi on 15/11/15.
//  Copyright © 2015年 HuCongshi. All rights reserved.
//

#import "ResourceViewController.h"
#import "RoomViewController.h"
@interface ResourceViewController ()
@property (nonatomic, strong) UITableView *baseTables;
@property (nonatomic, strong) NSArray *lists;
@end

@implementation ResourceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initData];
    [self initItems];
    
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated{
    [self initData];
    [self initItems];
}
- (void) iniNavi{
    [self.navigationController pushViewController:self animated:YES];
}
- (void) initData{
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *plistPath = [bundle pathForResource:@"dev" ofType:@"plist"];
    self.lists = [[NSArray alloc] initWithContentsOfFile:plistPath];}
- (void)initItems{
    CGRect rx = [UIScreen mainScreen].bounds;
    UIView *banner = [[UIView alloc] initWithFrame:CGRectMake(0, 0, rx.size.width, 130)];
    banner.backgroundColor = [UIColor blueColor];
    [self.view addSubview:banner];
    
    UIImageView *logo = [[UIImageView alloc] initWithFrame:CGRectMake(5,5,176,126)];
    logo.image = [UIImage imageNamed:@"logo.png"];
    [self.view addSubview:logo];
    
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(180, 30, 500, 80)];
    title.text = @"云资源管理系统";
    title.textColor = [UIColor whiteColor];
    title.font = [UIFont systemFontOfSize:36];
    title.textAlignment = NSTextAlignmentLeft;
    [self.view addSubview:title];
    
    UIView *vLine1 = [[UIView alloc] initWithFrame:CGRectMake(0, 190, rx.size.width, 2)];
    vLine1.backgroundColor = [UIColor blueColor];
    [self.view addSubview:vLine1];
    
    UIView *hLine = [[UIView alloc] initWithFrame:CGRectMake(rx.size.width/4.0, 192, 2, rx.size.height-292)];
    hLine.backgroundColor = [UIColor blueColor];
    [self.view addSubview:hLine];
    
    UIView *vLine2 = [[UIView alloc] initWithFrame:CGRectMake(rx.size.width/4.0, 192+(rx.size.height-292)/3.0, rx.size.width/4.0*3, 2)];
    vLine2.backgroundColor = [UIColor blueColor];
    [self.view addSubview:vLine2];
    
    UIView *vLine3 = [[UIView alloc] initWithFrame:CGRectMake(rx.size.width/4.0, 192+(rx.size.height-292)/3.0*2, rx.size.width/4.0*3, 2)];
    vLine3.backgroundColor = [UIColor blueColor];
    [self.view addSubview:vLine3];
    
    UIView *navi = [[UIView alloc] initWithFrame:CGRectMake(5, 135, 300, 50)];
    //navi.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:navi];
    
    UIImageView *arrow = [[UIImageView alloc] initWithFrame:CGRectMake(0, 15, 60, 20)];
    arrow.image = [UIImage imageNamed:@"doublearrow.png"];
    [navi addSubview:arrow];
    
    UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(65, 5, 100, 40)];
    nameLabel.text = @"私有云";
    nameLabel.textColor = [UIColor blackColor];
    nameLabel.font = [UIFont systemFontOfSize:24];
    [navi addSubview:nameLabel];
    
    /////////////////////////////////////////////////
    self.baseTables = [[UITableView alloc] initWithFrame:CGRectMake(10, 200, rx.size.width/4-15, rx.size.height-110-200)];
    self.baseTables.delegate = self;
    self.baseTables.dataSource = self;
    [self.view addSubview:self.baseTables];
    
    UILabel *basetitle1 = [[UILabel alloc] initWithFrame:CGRectMake(rx.size.width/4.0+5, 195, 100, 40)];
    basetitle1.textColor = [UIColor blackColor];
    NSDictionary *base1 = [self.lists objectAtIndex:0];
    basetitle1.text = [base1 objectForKey:@"name"];
    basetitle1.font = [UIFont systemFontOfSize:24];
    [self.view addSubview:basetitle1];
    
    UITextView *basedis = [[UITextView alloc] initWithFrame:CGRectMake(rx.size.width/4.0+5, 230, rx.size.width/4.0*3-80, (rx.size.height-292)/3.0-40)];
    basedis.textColor = [UIColor blackColor];
    //basedis.backgroundColor = [UIColor orangeColor];
    basedis.text = [base1 objectForKey:@"discription"];
    basedis.font = [UIFont systemFontOfSize:16];
    basedis.editable = NO;
    [self.view addSubview:basedis];
    
    UILabel *basetitle2 = [[UILabel alloc] initWithFrame:CGRectMake(rx.size.width/4.0+5, 195+(rx.size.height-292)/3.0, 100, 40)];
    basetitle2.textColor = [UIColor blackColor];
    NSDictionary *base2 = [self.lists objectAtIndex:1];
    basetitle2.text = [base2 objectForKey:@"name"];
    basetitle2.font = [UIFont systemFontOfSize:24];
    [self.view addSubview:basetitle2];
    
    UITextView *basedis2 = [[UITextView alloc] initWithFrame:CGRectMake(rx.size.width/4.0+5, 230+(rx.size.height-292)/3.0, rx.size.width/4.0*3-80, (rx.size.height-292)/3.0-40)];
    basedis2.textColor = [UIColor blackColor];
    //basedis2.backgroundColor = [UIColor orangeColor];
    basedis2.text = [base2 objectForKey:@"discription"];
    basedis2.font = [UIFont systemFontOfSize:16];
    basedis2.editable = NO;
    [self.view addSubview:basedis2];
    
    UILabel *basetitle3 = [[UILabel alloc] initWithFrame:CGRectMake(rx.size.width/4.0+5, 195+(rx.size.height-292)/3.0*2, 100, 40)];
    basetitle3.textColor = [UIColor blackColor];
    NSDictionary *base3 = [self.lists objectAtIndex:2];
    basetitle3.text = [base3 objectForKey:@"name"];
    basetitle3.font = [UIFont systemFontOfSize:24];
    [self.view addSubview:basetitle3];
    
    UITextView *basedis3 = [[UITextView alloc] initWithFrame:CGRectMake(rx.size.width/4.0+5, 230+(rx.size.height-292)/3.0*2, rx.size.width/4.0*3-80, (rx.size.height-292)/3.0-40)];
    basedis3.textColor = [UIColor blackColor];
    //basedis3.backgroundColor = [UIColor orangeColor];
    basedis3.text = [base3 objectForKey:@"discription"];
    basedis3.font = [UIFont systemFontOfSize:16];
    basedis3.editable = NO;
    [self.view addSubview:basedis3];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark - UITableView
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"CellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    
    NSUInteger row = [indexPath row];
    NSDictionary *base = [self.lists objectAtIndex:row];
    cell.textLabel.text = [base objectForKey:@"name"];
    cell.textLabel.font = [UIFont systemFontOfSize:28];
    cell.textLabel.textColor = [UIColor blackColor];
    return cell;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.lists count];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGRect rx = [UIScreen mainScreen].bounds;
    return (rx.size.height-110-200)/3.0;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    RoomViewController *tp = [mainStoryboard instantiateViewControllerWithIdentifier:@"RoomViewController"];
    //NSDictionary *base = [self.lists objectAtIndex:indexPath.row];
    tp.baseID = indexPath.row;
    //tp.baseName = [base objectForKey:@"name"];
    [self.navigationController pushViewController:tp animated:YES];
    //[self presentViewController:tp animated:YES completion:nil];
}
@end
